package com.wenhuitec.sysui.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wenhuitec.sysui.R;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wenhuitec.sysui.entity.Foods;

import java.util.List;

public class FoodRecyclerAdapter extends RecyclerView.Adapter<FoodRecyclerAdapter.MyHolder> {


    List<Foods> mFoods;

    public FoodRecyclerAdapter() {

    }


    public FoodRecyclerAdapter(List<Foods> mFoods) {
        this.mFoods = mFoods;
    }

    @NonNull
    @Override
    public MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_food, parent, false);
        //将view传递给我们自定义的ViewHolder
        MyHolder holder = new MyHolder(view);
        //返回这个MyHolder实体
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull MyHolder holder, int position) {
        holder.name.setText(mFoods.get(position).getName());
        holder.num.setText(String.valueOf(mFoods.get(position).getNum()));
        holder.price.setText("￥" + mFoods.get(position).getPrice());
    }

    @Override
    public int getItemCount() {
        return mFoods.size();
    }


    class MyHolder extends RecyclerView.ViewHolder {

        TextView name;
        TextView num;
        TextView price;

        public MyHolder(View itemView) {
            super(itemView);
            name = itemView.findViewById(R.id.name);
            num = itemView.findViewById(R.id.num);
            price = itemView.findViewById(R.id.price);
        }
    }

}